<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
    
      <el-form-item label="资产名称" prop="assetName">
        <el-input
          v-model="queryParams.assetName"
          placeholder="请输入资产名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别名称" prop="categoryName">
        <el-input
          v-model="queryParams.categoryName"
          placeholder="请输入类别名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用部门" prop="useDepartment">
        <el-input
          v-model="queryParams.useDepartment"
          placeholder="请输入使用部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管理部门" prop="managementDepartment">
        <el-input
          v-model="queryParams.managementDepartment"
          placeholder="请输入管理部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用状况" prop="usageStatus">
  <el-select
    v-model="queryParams.usageStatus"
    placeholder="请选择使用状况"
    clearable
    style="width: 100%"
  >
    <el-option
      v-for="item in usageStatusOptions"
      :key="item.value"
      :label="item.label"
      :value="item.value"
    />
  </el-select>
</el-form-item>
      <el-form-item label="开始日期" prop="startDate">
        <el-date-picker clearable
          v-model="queryParams.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开始使用日期" style="width: 205px">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="本币原值" prop="localCurrencyValue">
        <el-input
          v-model="queryParams.localCurrencyValue"
          placeholder="请输入本币原值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用人" prop="userName" :style="{ 'text-align-last': 'justify' }">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入使用人"
          clearable
          @keyup.enter.native="handleQuery"
          :style="{ 'text-align-last': 'left!important' }"
        />
      </el-form-item>
      <el-form-item label="规格型号" prop="specificationModel">
        <el-input
          v-model="queryParams.specificationModel"
          placeholder="请输入规格型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存放地点" prop="storageLocation">
        <el-input
          v-model="queryParams.storageLocation"
          placeholder="请输入存放地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商" prop="supplier" :style="{ 'text-align-last': 'justify' }">
        <el-input
          v-model="queryParams.supplier"
          placeholder="请输入供应商"
          clearable
          @keyup.enter.native="handleQuery"
           :style="{ 'text-align-last': 'left!important' }"
        />
      </el-form-item>
      <el-form-item label="数量" prop="quantity" :style="{ 'text-align-last': 'justify' }">
        <el-input
          v-model="queryParams.quantity"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
          :style="{ 'text-align-last': 'left!important' }"
        />
      </el-form-item>
    
      <el-form-item label="资金来源" prop="fundingProgram">
        <el-input
          v-model="queryParams.fundingProgram"
          placeholder="请输入固定资产资金来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收支项目" prop="revenueExpenditureItem">
        <el-input
          v-model="queryParams.revenueExpenditureItem"
          placeholder="请输入固定资产收支项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item label="合同号" prop="contractNumber" :style="{ 'text-align-last': 'justify' }">
        <el-input
          v-model="queryParams.contractNumber"
          placeholder="请输入合同号"
          clearable
          @keyup.enter.native="handleQuery"
          :style="{ 'text-align-last': 'left!important' }"
        />
      </el-form-item>
      <el-form-item label="资产分类" prop="assetClassification">
        <el-input
          v-model="queryParams.assetClassification"
          placeholder="请输入资产分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5" hidden="true">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sci:fixedAssets:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5" hidden="true">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sci:fixedAssets:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5" hidden="true">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sci:fixedAssets:remove']"
        >删除</el-button>
      </el-col>
       <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['sci:fixedAssets:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sci:fixedAssets:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fixedAssetsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="资产名称" align="center" prop="assetName" />
      <el-table-column label="类别名称" align="center" prop="categoryName" />
      <el-table-column label="使用部门" align="center" prop="useDepartment" />
      <el-table-column label="管理部门" align="center" prop="managementDepartment" />
      <el-table-column label="使用状况" align="center" prop="usageStatus" />
      <el-table-column label="开始使用日期" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="本币原值" align="center" prop="localCurrencyValue" />
      <el-table-column label="使用人" align="center" prop="userName" />
      <el-table-column label="规格型号" align="center" prop="specificationModel" />
      <el-table-column label="存放地点" align="center" prop="storageLocation" />
      <el-table-column label="供应商" align="center" prop="supplier" />
      <el-table-column label="数量" align="center" prop="quantity" /
      <el-table-column label="固定资金来源" align="center" prop="fundingProgram" />
       <el-table-column label="收支项目" align="center" prop="revenueExpenditureItem" />
      <el-table-column label="合同号" align="center" prop="contractNumber" />
      <el-table-column label="资产分类" align="center" prop="assetClassification" />
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
       <template slot-scope="scope">
        <!--   <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:fixedAssets:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:fixedAssets:remove']"
          >删除</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
            v-hasPermi="['sci:fixedAssets:query']"
          >查看</el-button>
        </template>
      </el-table-column> 
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改研究院固定资产对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="卡片编号" prop="cardNumber">
          <el-input v-model="form.cardNumber" placeholder="请输入卡片编号" />
        </el-form-item>
        <el-form-item label="资产编码" prop="assetCode">
          <el-input v-model="form.assetCode" placeholder="请输入资产编码" />
        </el-form-item>
        <el-form-item label="资产名称" prop="assetName">
          <el-input v-model="form.assetName" placeholder="请输入资产名称" />
        </el-form-item>
        <el-form-item label="类别名称" prop="categoryName">
          <el-input v-model="form.categoryName" placeholder="请输入类别名称" />
        </el-form-item>
        <el-form-item label="币种" prop="currency">
          <el-input v-model="form.currency" placeholder="请输入币种" />
        </el-form-item>
        <el-form-item label="折旧方法" prop="depreciationMethod">
          <el-input v-model="form.depreciationMethod" placeholder="请输入折旧方法" />
        </el-form-item>
        <el-form-item label="使用部门" prop="useDepartment">
          <el-input v-model="form.useDepartment" placeholder="请输入使用部门" />
        </el-form-item>
        <el-form-item label="管理部门" prop="managementDepartment">
          <el-input v-model="form.managementDepartment" placeholder="请输入管理部门" />
        </el-form-item>
        <el-form-item label="增加方式" prop="acquisitionMethod">
          <el-input v-model="form.acquisitionMethod" placeholder="请输入增加方式" />
        </el-form-item>
        <el-form-item label="折旧承担部门" prop="depreciationDepartment">
          <el-input v-model="form.depreciationDepartment" placeholder="请输入折旧承担部门" />
        </el-form-item>
        <el-form-item label="已计提月份" prop="accruedMonths">
          <el-input v-model="form.accruedMonths" placeholder="请输入已计提月份" />
        </el-form-item>
        <el-form-item label="开始使用日期" prop="startDate">
          <el-date-picker clearable
            v-model="form.startDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开始使用日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="原币原值" prop="originalCurrencyValue">
          <el-input v-model="form.originalCurrencyValue" placeholder="请输入原币原值" />
        </el-form-item>
        <el-form-item label="本币原值" prop="localCurrencyValue">
          <el-input v-model="form.localCurrencyValue" placeholder="请输入本币原值" />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnit">
          <el-input v-model="form.monetaryUnit" placeholder="请输入货币单位" />
        </el-form-item>
        <el-form-item label="累计折旧" prop="accumulatedDepreciation">
          <el-input v-model="form.accumulatedDepreciation" placeholder="请输入累计折旧" />
        </el-form-item>
        <el-form-item label="净残值率％" prop="residualRate">
          <el-input v-model="form.residualRate" placeholder="请输入净残值率％" />
        </el-form-item>
        <el-form-item label="使用人" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入使用人" />
        </el-form-item>
        <el-form-item label="使用月限" prop="usageMonths">
          <el-input v-model="form.usageMonths" placeholder="请输入使用月限" />
        </el-form-item>
        <el-form-item label="单位折旧" prop="unitDepreciation">
          <el-input v-model="form.unitDepreciation" placeholder="请输入单位折旧" />
        </el-form-item>
        <el-form-item label="月折旧率" prop="monthlyDepreciationRate">
          <el-input v-model="form.monthlyDepreciationRate" placeholder="请输入月折旧率" />
        </el-form-item>
        <el-form-item label="月折旧额" prop="monthlyDepreciationAmount">
          <el-input v-model="form.monthlyDepreciationAmount" placeholder="请输入月折旧额" />
        </el-form-item>
        <el-form-item label="规格型号" prop="specificationModel">
          <el-input v-model="form.specificationModel" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="存放地点" prop="storageLocation">
          <el-input v-model="form.storageLocation" placeholder="请输入存放地点" />
        </el-form-item>
        <el-form-item label="工作量单位" prop="workloadUnit">
          <el-input v-model="form.workloadUnit" placeholder="请输入工作量单位" />
        </el-form-item>
        <el-form-item label="累计工作量" prop="cumulativeWorkload">
          <el-input v-model="form.cumulativeWorkload" placeholder="请输入累计工作量" />
        </el-form-item>
        <el-form-item label="工作总量" prop="totalWorkload">
          <el-input v-model="form.totalWorkload" placeholder="请输入工作总量" />
        </el-form-item>
        <el-form-item label="减值准备" prop="impairmentProvision">
          <el-input v-model="form.impairmentProvision" placeholder="请输入减值准备" />
        </el-form-item>
        <el-form-item label="类别编码" prop="categoryCode">
          <el-input v-model="form.categoryCode" placeholder="请输入类别编码" />
        </el-form-item>
        <el-form-item label="净值" prop="netValue">
          <el-input v-model="form.netValue" placeholder="请输入净值" />
        </el-form-item>
        <el-form-item label="净残值" prop="residualValue">
          <el-input v-model="form.residualValue" placeholder="请输入净残值" />
        </el-form-item>
        <el-form-item label="净额" prop="netAmount">
          <el-input v-model="form.netAmount" placeholder="请输入净额" />
        </el-form-item>
        <el-form-item label="资产套号" prop="assetSetNumber">
          <el-input v-model="form.assetSetNumber" placeholder="请输入资产套号" />
        </el-form-item>
        <el-form-item label="月工作量" prop="monthlyWorkload">
          <el-input v-model="form.monthlyWorkload" placeholder="请输入月工作量" />
        </el-form-item>
        <el-form-item label="供应商" prop="supplier">
          <el-input v-model="form.supplier" placeholder="请输入供应商" />
        </el-form-item>
        <el-form-item label="资产组" prop="assetGroup">
          <el-input v-model="form.assetGroup" placeholder="请输入资产组" />
        </el-form-item>
        <el-form-item label="评估值" prop="assessedValue">
          <el-input v-model="form.assessedValue" placeholder="请输入评估值" />
        </el-form-item>
        <el-form-item label="相关税费" prop="relatedTaxes">
          <el-input v-model="form.relatedTaxes" placeholder="请输入相关税费" />
        </el-form-item>
        <el-form-item label="弃置费用" prop="abandonmentCost">
          <el-input v-model="form.abandonmentCost" placeholder="请输入弃置费用" />
        </el-form-item>
        <el-form-item label="其他费用" prop="otherCosts">
          <el-input v-model="form.otherCosts" placeholder="请输入其他费用" />
        </el-form-item>
        <el-form-item label="条形码" prop="barcode">
          <el-input v-model="form.barcode" placeholder="请输入条形码" />
        </el-form-item>
        <el-form-item label="保修截止日期" prop="warrantyExpiry">
          <el-date-picker clearable
            v-model="form.warrantyExpiry"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择保修截止日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="进项税" prop="inputTax">
          <el-input v-model="form.inputTax" placeholder="请输入进项税" />
        </el-form-item>
        <el-form-item label="抵扣进项税" prop="deductibleInputTax">
          <el-input v-model="form.deductibleInputTax" placeholder="请输入抵扣进项税" />
        </el-form-item>
        <el-form-item label="安装调试费" prop="installationDebuggingFee">
          <el-input v-model="form.installationDebuggingFee" placeholder="请输入安装调试费" />
        </el-form-item>
        <el-form-item label="购买价款" prop="purchasePrice">
          <el-input v-model="form.purchasePrice" placeholder="请输入购买价款" />
        </el-form-item>
        <el-form-item label="工作中心" prop="workCenter">
          <el-input v-model="form.workCenter" placeholder="请输入工作中心" />
        </el-form-item>
        <el-form-item label="数量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="项目管理档案" prop="projectManagementArchive">
          <el-input v-model="form.projectManagementArchive" placeholder="请输入项目管理档案" />
        </el-form-item>
        <el-form-item label="车辆牌照号" prop="vehicleLicensePlate">
          <el-input v-model="form.vehicleLicensePlate" placeholder="请输入车辆牌照号" />
        </el-form-item>
        <el-form-item label="净吨位" prop="netTonnage">
          <el-input v-model="form.netTonnage" placeholder="请输入净吨位" />
        </el-form-item>
        <el-form-item label="资金来源" prop="fundingSource">
          <el-input v-model="form.fundingSource" placeholder="请输入资金来源" />
        </el-form-item>
        <el-form-item label="土地级别" prop="landLevel">
          <el-input v-model="form.landLevel" placeholder="请输入土地级别" />
        </el-form-item>
        <el-form-item label="计量单位" prop="measurementUnit">
          <el-input v-model="form.measurementUnit" placeholder="请输入计量单位" />
        </el-form-item>
        <el-form-item label="土地面积" prop="landArea">
          <el-input v-model="form.landArea" placeholder="请输入土地面积" />
        </el-form-item>
        <el-form-item label="建筑面积" prop="floorArea">
          <el-input v-model="form.floorArea" placeholder="请输入建筑面积" />
        </el-form-item>
        <el-form-item label="间[座]数" prop="buildingCount">
          <el-input v-model="form.buildingCount" placeholder="请输入间[座]数" />
        </el-form-item>
        <el-form-item label="建筑承包商" prop="buildingContractor">
          <el-input v-model="form.buildingContractor" placeholder="请输入建筑承包商" />
        </el-form-item>
        <el-form-item label="电机功率" prop="motorPower">
          <el-input v-model="form.motorPower" placeholder="请输入电机功率" />
        </el-form-item>
        <el-form-item label="电机数量" prop="motorQuantity">
          <el-input v-model="form.motorQuantity" placeholder="请输入电机数量" />
        </el-form-item>
        <el-form-item label="出厂日期" prop="productionDate">
          <el-date-picker clearable
            v-model="form.productionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出厂日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产厂商" prop="manufacturer">
          <el-input v-model="form.manufacturer" placeholder="请输入生产厂商" />
        </el-form-item>
        <el-form-item label="已折旧计提月份" prop="depreciationAccruedMonths">
          <el-input v-model="form.depreciationAccruedMonths" placeholder="请输入已折旧计提月份" />
        </el-form-item>
        <el-form-item label="固定资产资金来源" prop="fundingProgram">
          <el-input v-model="form.fundingProgram" placeholder="请输入固定资产资金来源" />
        </el-form-item>
        <el-form-item label="固定资产收支项目" prop="revenueExpenditureItem">
          <el-input v-model="form.revenueExpenditureItem" placeholder="请输入固定资产收支项目" />
        </el-form-item>
        <el-form-item label="税率" prop="taxRate">
          <el-input v-model="form.taxRate" placeholder="请输入税率" />
        </el-form-item>
        <el-form-item label="车辆购置税" prop="vehiclePurchaseTax">
          <el-input v-model="form.vehiclePurchaseTax" placeholder="请输入车辆购置税" />
        </el-form-item>
        <el-form-item label="耕地占用税" prop="farmlandOccupationTax">
          <el-input v-model="form.farmlandOccupationTax" placeholder="请输入耕地占用税" />
        </el-form-item>
        <el-form-item label="关税" prop="customsDuty">
          <el-input v-model="form.customsDuty" placeholder="请输入关税" />
        </el-form-item>
        <el-form-item label="契税" prop="deedTax">
          <el-input v-model="form.deedTax" placeholder="请输入契税" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractNumber">
          <el-input v-model="form.contractNumber" placeholder="请输入合同号" />
        </el-form-item>
        <el-form-item label="资产分类" prop="assetClassification">
          <el-input v-model="form.assetClassification" placeholder="请输入资产分类" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
     <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="600px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看抽屉 -->
    <el-drawer
      title="固定资产详情"
      :visible.sync="drawer"
      size="50%"
      direction="rtl"
    >
      <el-card shadow="always" style="margin: 20px;">
        <el-descriptions title="基本信息" :column="2" border>
          <el-descriptions-item label="资产名称">{{ formView.assetName }}</el-descriptions-item>
          <el-descriptions-item label="类别名称">{{ formView.categoryName }}</el-descriptions-item>
          <el-descriptions-item label="使用部门">{{ formView.useDepartment }}</el-descriptions-item>
          <el-descriptions-item label="管理部门">{{ formView.managementDepartment }}</el-descriptions-item>
          <el-descriptions-item label="使用状况">{{ formView.usageStatus}}</el-descriptions-item>
          <el-descriptions-item label="开始使用日期">{{ parseTime(formView.startDate, '{y}-{m}-{d}') }}</el-descriptions-item>
          <el-descriptions-item label="本币原值">{{ formView.localCurrencyValue }}</el-descriptions-item>
          <el-descriptions-item label="使用人">{{ formView.userName }}</el-descriptions-item>
          <el-descriptions-item label="规格型号">{{ formView.specificationModel }}</el-descriptions-item>
          <el-descriptions-item label="存放地点">{{ formView.storageLocation }}</el-descriptions-item>
          <el-descriptions-item label="供应商">{{ formView.supplier }}</el-descriptions-item>
          <el-descriptions-item label="数量">{{ formView.quantity }}</el-descriptions-item>
        </el-descriptions>
      </el-card>

      <el-card shadow="always" style="margin: 20px;">
        <el-descriptions title="财务信息" :column="2" border>
          <el-descriptions-item label="原币原值">{{ formView.originalCurrencyValue }}</el-descriptions-item>
          <el-descriptions-item label="累计折旧">{{ formView.accumulatedDepreciation }}</el-descriptions-item>
          <el-descriptions-item label="净值">{{ formView.netValue }}</el-descriptions-item>
          <el-descriptions-item label="净残值">{{ formView.residualValue }}</el-descriptions-item>
          <el-descriptions-item label="税率">{{ formView.taxRate }}</el-descriptions-item>
          <el-descriptions-item label="进项税">{{ formView.inputTax }}</el-descriptions-item>
          <el-descriptions-item label="抵扣进项税">{{ formView.deductibleInputTax }}</el-descriptions-item>
          <el-descriptions-item label="安装调试费">{{ formView.installationDebuggingFee }}</el-descriptions-item>
          <el-descriptions-item label="购买价款">{{ formView.purchasePrice }}</el-descriptions-item>
          <el-descriptions-item label="其他费用">{{ formView.otherCosts }}</el-descriptions-item>
        </el-descriptions>
      </el-card>

      <el-card shadow="always" style="margin: 20px;">
        <el-descriptions title="其他信息" :column="2" border>
          <el-descriptions-item label="资金来源">{{ formView.fundingSource }}</el-descriptions-item>
          <el-descriptions-item label="收支项目">{{ formView.revenueExpenditureItem }}</el-descriptions-item>
          <el-descriptions-item label="合同号">{{ formView.contractNumber }}</el-descriptions-item>
          <el-descriptions-item label="资产分类">{{ formView.assetClassification }}</el-descriptions-item>
          <el-descriptions-item label="计量单位">{{ formView.measurementUnit }}</el-descriptions-item>
          <el-descriptions-item label="条形码">{{ formView.barcode }}</el-descriptions-item>
          <el-descriptions-item label="保修截止日期">{{ parseTime(formView.warrantyExpiry, '{y}-{m}-{d}') }}</el-descriptions-item>
          <el-descriptions-item label="出厂日期">{{ parseTime(formView.productionDate, '{y}-{m}-{d}') }}</el-descriptions-item>
          <el-descriptions-item label="生产厂商">{{ formView.manufacturer }}</el-descriptions-item>
        </el-descriptions>
      </el-card>
    </el-drawer>
  </div>
</template>

<script>
import { listFixedAssets, getFixedAssets, delFixedAssets, addFixedAssets, updateFixedAssets } from "@/api/sci/fixedAssets";
import { listDept } from '@/api/system/dept';
import { listUserByDeptId,listUser } from '@/api/system/user';
import { listProject } from '@/api/sci/project';
import { getToken } from "@/utils/auth";

export default {
  name: "FixedAssets",
  data() {
    return {
       drawer: false, // 控制抽屉显示
      formView: {},   // 查看表单数据
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 研究院固定资产表格数据
      fixedAssetsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cardNumber: null,
        assetCode: null,
        assetName: null,
        categoryName: null,
        currency: null,
        depreciationMethod: null,
        useDepartment: null,
        managementDepartment: null,
        acquisitionMethod: null,
        usageStatus: null,
        depreciationDepartment: null,
        accruedMonths: null,
        startDate: null,
        originalCurrencyValue: null,
        localCurrencyValue: null,
        monetaryUnit: null,
        accumulatedDepreciation: null,
        residualRate: null,
        userName: null,
        usageMonths: null,
        unitDepreciation: null,
        monthlyDepreciationRate: null,
        monthlyDepreciationAmount: null,
        specificationModel: null,
        storageLocation: null,
        workloadUnit: null,
        cumulativeWorkload: null,
        totalWorkload: null,
        impairmentProvision: null,
        categoryCode: null,
        netValue: null,
        residualValue: null,
        netAmount: null,
        assetSetNumber: null,
        monthlyWorkload: null,
        supplier: null,
        assetGroup: null,
        assessedValue: null,
        relatedTaxes: null,
        abandonmentCost: null,
        otherCosts: null,
        barcode: null,
        warrantyExpiry: null,
        inputTax: null,
        deductibleInputTax: null,
        installationDebuggingFee: null,
        purchasePrice: null,
        workCenter: null,
        quantity: null,
        projectManagementArchive: null,
        vehicleLicensePlate: null,
        netTonnage: null,
        fundingSource: null,
        landLevel: null,
        measurementUnit: null,
        landArea: null,
        floorArea: null,
        buildingCount: null,
        buildingContractor: null,
        motorPower: null,
        motorQuantity: null,
        productionDate: null,
        manufacturer: null,
        depreciationAccruedMonths: null,
        fundingProgram: null,
        revenueExpenditureItem: null,
        taxRate: null,
        vehiclePurchaseTax: null,
        farmlandOccupationTax: null,
        customsDuty: null,
        deedTax: null,
        contractNumber: null,
        assetClassification: null,
         usageStatus: '' // 使用状态
      },
     
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cardNumber: [
          { required: true, message: "卡片编号不能为空", trigger: "blur" }
        ],
        assetCode: [
          { required: true, message: "资产编码不能为空", trigger: "blur" }
        ],
        assetName: [
          { required: true, message: "资产名称不能为空", trigger: "blur" }
        ],
        categoryName: [
          { required: true, message: "类别名称不能为空", trigger: "blur" }
        ],
        currency: [
          { required: true, message: "币种不能为空", trigger: "blur" }
        ],
        depreciationMethod: [
          { required: true, message: "折旧方法不能为空", trigger: "blur" }
        ],
        useDepartment: [
          { required: true, message: "使用部门不能为空", trigger: "blur" }
        ],
        managementDepartment: [
          { required: true, message: "管理部门不能为空", trigger: "blur" }
        ],
        acquisitionMethod: [
          { required: true, message: "增加方式不能为空", trigger: "blur" }
        ],
        usageStatus: [
          { required: true, message: "使用状况不能为空", trigger: "change" }
        ],
        depreciationDepartment: [
          { required: true, message: "折旧承担部门不能为空", trigger: "blur" }
        ],
        accruedMonths: [
          { required: true, message: "已计提月份不能为空", trigger: "blur" }
        ],
        startDate: [
          { required: true, message: "开始使用日期不能为空", trigger: "blur" }
        ],
        originalCurrencyValue: [
          { required: true, message: "原币原值不能为空", trigger: "blur" }
        ],
        localCurrencyValue: [
          { required: true, message: "本币原值不能为空", trigger: "blur" }
        ],
        monetaryUnit: [
          { required: true, message: "货币单位不能为空", trigger: "blur" }
        ],
        accumulatedDepreciation: [
          { required: true, message: "累计折旧不能为空", trigger: "blur" }
        ],
        userName: [
          { required: true, message: "使用人不能为空", trigger: "blur" }
        ],
        usageMonths: [
          { required: true, message: "使用月限不能为空", trigger: "blur" }
        ],
        storageLocation: [
          { required: true, message: "存放地点不能为空", trigger: "blur" }
        ],
        categoryCode: [
          { required: true, message: "类别编码不能为空", trigger: "blur" }
        ],
        netValue: [
          { required: true, message: "净值不能为空", trigger: "blur" }
        ],
        netAmount: [
          { required: true, message: "净额不能为空", trigger: "blur" }
        ],
        supplier: [
          { required: true, message: "供应商不能为空", trigger: "blur" }
        ],
        quantity: [
          { required: true, message: "数量不能为空", trigger: "blur" }
        ],
        fundingSource: [
          { required: true, message: "资金来源不能为空", trigger: "blur" }
        ],
        measurementUnit: [
          { required: true, message: "计量单位不能为空", trigger: "blur" }
        ],
        fundingProgram: [
          { required: true, message: "固定资产资金来源不能为空", trigger: "blur" }
        ],
        revenueExpenditureItem: [
          { required: true, message: "固定资产收支项目不能为空", trigger: "blur" }
        ],
        taxRate: [
          { required: true, message: "税率不能为空", trigger: "blur" }
        ],
        assetClassification: [
          { required: true, message: "资产分类不能为空", trigger: "blur" }
        ],
      }, // 设备导入参数
      upload: {
        // 是否显示弹出层（设备导入）
        open: false,
        // 弹出层标题（设备导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/fixedAssets/importData"
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {

    /** 查看按钮操作 */
    handleView(row) {
      const id = row.id || this.ids;
      getFixedAssets(id).then(response => {
        this.formView = response.data;
        this.drawer = true;
      });
    },
     // 时间格式化方法
    parseTime(time, format = '{y}-{m}-{d} {h}:{i}:{s}') {
      if (!time) return '';
      let date = new Date(time);
      const formatObj = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds()
      };
      return format.replace(/{([ymdhisa])+}/g, (result, key) => {
        const value = formatObj[key];
        return value.toString().padStart(2, '0');
      });
    },
    /** 查询研究院固定资产列表 */
    getList() {
      this.loading = true;
      listFixedAssets(this.queryParams).then(response => {
        this.fixedAssetsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cardNumber: null,
        assetCode: null,
        assetName: null,
        categoryName: null,
        currency: null,
        depreciationMethod: null,
        useDepartment: null,
        managementDepartment: null,
        acquisitionMethod: null,
        usageStatus: null,
        depreciationDepartment: null,
        accruedMonths: null,
        startDate: null,
        originalCurrencyValue: null,
        localCurrencyValue: null,
        monetaryUnit: null,
        accumulatedDepreciation: null,
        residualRate: null,
        userName: null,
        usageMonths: null,
        unitDepreciation: null,
        monthlyDepreciationRate: null,
        monthlyDepreciationAmount: null,
        specificationModel: null,
        storageLocation: null,
        workloadUnit: null,
        cumulativeWorkload: null,
        totalWorkload: null,
        impairmentProvision: null,
        categoryCode: null,
        netValue: null,
        residualValue: null,
        netAmount: null,
        assetSetNumber: null,
        monthlyWorkload: null,
        supplier: null,
        assetGroup: null,
        assessedValue: null,
        relatedTaxes: null,
        abandonmentCost: null,
        otherCosts: null,
        barcode: null,
        warrantyExpiry: null,
        inputTax: null,
        deductibleInputTax: null,
        installationDebuggingFee: null,
        purchasePrice: null,
        workCenter: null,
        quantity: null,
        projectManagementArchive: null,
        vehicleLicensePlate: null,
        netTonnage: null,
        fundingSource: null,
        landLevel: null,
        measurementUnit: null,
        landArea: null,
        floorArea: null,
        buildingCount: null,
        buildingContractor: null,
        motorPower: null,
        motorQuantity: null,
        productionDate: null,
        manufacturer: null,
        depreciationAccruedMonths: null,
        fundingProgram: null,
        revenueExpenditureItem: null,
        taxRate: null,
        vehiclePurchaseTax: null,
        farmlandOccupationTax: null,
        customsDuty: null,
        deedTax: null,
        contractNumber: null,
        assetClassification: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加研究院固定资产";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFixedAssets(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改研究院固定资产";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFixedAssets(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFixedAssets(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
       /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "设备导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/fixedAssets/importTemplate', {
      }, `fixed_assets_template_${new Date().getTime()}.xlsx`)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除研究院固定资产编号为"' + ids + '"的数据项？').then(function() {
        return delFixedAssets(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/fixedAssets/export', {
        ...this.queryParams
      }, `fixedAssets_${new Date().getTime()}.xlsx`)
    },
    handleFileUploadProgress(event, file, fileList) {
  this.upload.isUploading = true;
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
  this.upload.open = false;
  this.upload.isUploading = false;
  this.$refs.upload.clearFiles();
  this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + 
    response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
  this.getList();
},
// 提交上传文件
submitFileForm() {
  this.$refs.upload.submit();
}
  }
};
</script>

<style scoped>
.el-form-item .el-input__inner {
  text-align: left !important;
}
/* 添加抽屉内容的样式 */
.el-drawer__body {
  padding: 0;
  overflow-y: auto;
}

.el-card {
  margin-bottom: 15px;
}

.el-descriptions__title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 15px;
}
</style>